<template>
  <div class="app-container">
    <eHeader :param-bean="paramBean" :sup_this="sup_this" />
    <eForm ref="form" :sup_this="sup_this" />
    <historyList ref="historyList" :sup_this="sup_this" />
    <!--表格渲染-->
    <DataGridTable
      v-loading="loading"
      ref="mainTable"
      :sup_this="sup_this"
      :data="data.rtnList"
      :max-height="gridMaxHeight"
      :total="total"
      :show-cell-class="true"
      :show-row-complex-number="true"
      :all-define-columns="['sysOrgName','busOtherCpyName','busDate','selfStateName','orderCode','itemCode','prodQty','finishProdQty','moStatus','scheduleBeginDate','scheduleEndDate','actualBeginDate','actualEndDate','mrpCode','lastUpdateDate']"
      grid-id="oemMoMngProcessGridId"
      @toViewHistory="toViewHistory"
      @selection-change="handleGridSelectionChange">
      <DataGridColumnSlot prop="sysGenCode" label="业务类型">
        <template slot-scope="scope">
          <edit :data="scope.row" :sup_this="sup_this" />
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="sysOrgName" prop="sysOrgName" label="机构" />
      <DataGridColumn slot="busOtherCpyName" prop="busOtherCpyName" label="供应商"/>
      <DataGridColumnSlot slot="busDate" prop="busDate" label="业务时间">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.busDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="selfStateName" prop="selfStateName" label="状态"/>
      <DataGridColumn slot="bomCode" prop="bomCode" label="BOM编码" />
      <DataGridColumn slot="orderCode" prop="orderCode" label="订单号" />
      <DataGridColumn slot="itemCode" prop="itemCode" label="生产物料" />
      <DataGridColumn slot="prodQty" prop="prodQty" label="生产数" />
      <DataGridColumn slot="finishProdQty" prop="finishProdQty" label="已完成生产数" />
      <DataGridColumnSlot slot="moStatus" prop="moStatus" label="MO状态">
        <template slot-scope="scope">
          <template v-for="(item) in dicts.mo_status">
            <el-tag v-if="item.dictCode === scope.row.moStatus" :type="item.attribute1" :key="item.id">{{ item.dictName }}</el-tag>
          </template>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="scheduleBeginDate" prop="scheduleBeginDate" label="预计开工日期" >
        <template slot-scope="scope">
          <span>{{ parseDate(scope.row.scheduleBeginDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="scheduleEndDate" prop="scheduleEndDate" label="预计结束日期" >
        <template slot-scope="scope">
          <span>{{ parseDate(scope.row.scheduleEndDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="actualBeginDate" prop="actualBeginDate" label="实际开工日期" >
        <template slot-scope="scope">
          <span>{{ parseDate(scope.row.actualBeginDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumnSlot slot="actualEndDate" prop="actualEndDate" label="实际结束日期" >
        <template slot-scope="scope">
          <span>{{ parseDate(scope.row.actualEndDate) }}</span>
        </template>
      </DataGridColumnSlot>
      <DataGridColumn slot="mrpCode" prop="mrpCode" label="MRP计划编号" />
      <DataGridColumnSlot slot="lastUpdateDate" prop="lastUpdateDate" label="最后更新时间" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastUpdateDate) }}</span>
        </template>
      </DataGridColumnSlot>
    </DataGridTable>
  </div>
</template>

<script>
import { parseTime, parseDate } from '@/utils/index'
import eHeader from './module/emsHeader'
import edit from './module/edit'
import eForm from './module/emsForm'
import historyList from './module/historyList'
import initData from '@/mixins/initData'
import emsMo from '@/api/prod/EmsMo'

export default {
  components: { eHeader, eForm, edit, historyList },
  dictTypes: ['mo_status'],
  mixins: [initData],
  props: {
  },
  data() {
    return {
      delLoading: false,
      sup_this: this
    }
  },
  created() {
    this.url = emsMo.loadDataUrl()
    this.defaultParamBean.selfStateList = ['0', '5', '4', '10'] // 默认加载草稿，待审批，审批不通过的数据
    this.$nextTick(() => {
      this.resetQuery(true)
    })
  },
  mounted() {
  },
  methods: {
    parseTime,
    parseDate,
    toViewHistory(row) {
      this.openViewHistory(row, 'historyList')
    },
    async beforeInit() {
      return true
    }
  }
}
</script>
